package com.whf.android.jar.util;


import org.jetbrains.annotations.NotNull;

import java.util.Random;

/**
 * 生成随机数
 *
 * @author qf
 * @version 1.0
 */
public final class RandomUntil {


    /**
     * @param endNum：生成一个0到endNum的随机数
     */
    public static int getHum(int endNum) {
        if (endNum > 0) {
            Random random = new Random();
            return random.nextInt(endNum);
        }
        return 0;
    }


    /**
     * @param startHum:生成一个startHum到endNum之间的随机效
     * @param endNum:生成一个startHum到endNum之间的随机效
     */
    public static int getHum(int startHum, int endNum) {
        if (endNum > startHum) {
            Random random = new Random();
            return random.nextInt(endNum - startHum) + startHum;
        }
        return 0;
    }

    /**
     * 生成随机大写字母
     */
    @NotNull
    public static String getLargeLetter() {
        Random random = new Random();
        return String.valueOf((char) (random.nextInt(27) + 'A'));
    }

    /**
     * @param size：生成随机大写字母字符串
     */
    @NotNull
    public static String getLargeLetter(int size) {
        StringBuilder stringBuffer = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            stringBuffer.append((char) (random.nextInt(27) + 'A'));
        }
        return stringBuffer.toString();
    }

    /**
     * 生成随机小写字母
     */
    @NotNull
    public static String getSmallLetter() {
        Random random = new Random();
        return String.valueOf((char) (random.nextInt(27) + 'a'));
    }

    /**
     * @param size：生成随机小写字母字符串
     */
    @NotNull
    public static String getSmallLetter(int size) {
        StringBuilder stringBuffer = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            stringBuffer.append((char) (random.nextInt(27) + 'a'));
        }
        return stringBuffer.toString();
    }

    /**
     * @param size：生成随机小写字母数字混合字符串
     */
    @NotNull
    public static String getHumLargeLetter(int size) {
        StringBuilder buffer = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            if (random.nextInt(2) % 2 == 0) {
                //字母
                buffer.append((char) (random.nextInt(27) + 'A'));
            } else {
                //数字
                buffer.append(random.nextInt(10));
            }
        }
        return buffer.toString();
    }

    /**
     * @param size：生成随机小写字母数字混合字符串
     */
    @NotNull
    public static String getHumSmallLetter(int size) {
        StringBuilder buffer = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            if (random.nextInt(2) % 2 == 0) {
                //字母
                buffer.append((char) (random.nextInt(27) + 'a'));
            } else {
                //数字
                buffer.append(random.nextInt(10));
            }
        }
        return buffer.toString();
    }

    /**
     * @param size：生成随机大小写字母数字混合字符串
     */
    @NotNull
    public static String getNumLargeSmallLetter(int size) {
        StringBuilder buffer = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            if (random.nextInt(2) % 2 == 0) {
                //字母
                if (random.nextInt(2) % 2 == 0) {
                    buffer.append((char) (random.nextInt(27) + 'A'));
                } else {
                    buffer.append((char) (random.nextInt(27) + 'a'));
                }
            } else {
                //数字
                buffer.append(random.nextInt(10));
            }

        }
        return buffer.toString();
    }
}